﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Controls
{
    public partial class ContentHoiDap : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_HoiDap", "HoiDap_ID"));
            string name = txtUsername.Text;
            string address = txtAddress.Text;
            string dienthoai = txtDienThoai.Text;
            string email = txtEmail1.Text;
            string tieude = txtTieuDe.Text;
            string title = txtTieuDe.Text;
            string noidung = txtNoiDung.Text;
            string traloi = "";
            string active = "0";
            DateTime datimelienhe = DateTime.Now;
            if (nextid == 0)
            {
                string value = "1, N'" + name + "', N'" + address + "', N'" + dienthoai + "', N'" + email + "', N'" + tieude + "', '" + title + "', N'" + noidung + "', '" + traloi + "', '" + active + "', '" + datimelienhe + "' ";
                List<string> values = new List<string>();
                values.Add(value);
                DAL.DCollector.DBCollector.Instance.Insert("tbl_HoiDap", values, false);
                Response.Redirect(Request.Url.ToString());
            }
            else
            {
                int idnext = nextid + 1;
                string value = "'"+ idnext +"', N'" + name + "', N'" + address + "', N'" + dienthoai + "', N'" + email + "', N'" + tieude + "', '" + title + "', N'" + noidung + "', '" + traloi + "', '" + active + "', '" + datimelienhe + "' ";
                List<string> values = new List<string>();
                values.Add(value);
                DAL.DCollector.DBCollector.Instance.Insert("tbl_HoiDap", values, false);
                Response.Redirect(Request.Url.ToString());
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtUsername.Text = "";
            txtAddress.Text = "";
            txtDienThoai.Text = "";
            txtEmail1.Text = "";
            txtTieuDe.Text = "";
            txtNoiDung.Text = "";
        }
    }
}